<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
class D
{
	private $CI;

	public function __construct()
	{
		$this->CI = &get_instance();
	}

	public function insert($a, $d)
	{
		return $this->CI->db->insert($a['table'], $d);
	}

	public function update($a, $d)
	{
		return $this->CI->db->where($a['where'])->update($a['table'], $d);
	}

	public function find($a)
	{
		if (isset($a['where'])) {
			$this->CI->db->where($a['where']);
		}

		if (isset($a['order'])) {
			$this->CI->db->order_by($a['order']);
		}

		return $this->CI->db->get($a['table'])->unbuffered_row('array');
	}

	public function field($a)
	{
		if (isset($a['where']) && $a['where']) {
			$this->CI->db->where($a['where']);
		}

		if (isset($a['order_by']) && $a['order_by']) {
			$this->CI->db->order_by($a['order_by']);
		}

		$row = $this->CI->db->select($a['field'])->get($a['table'])->unbuffered_row('array');
		return $row[$a['field']];
	}

	public function rows($a)
	{
		if (isset($a['select'])) {
			$this->CI->db->select($a['select']);
		}

		if (isset($a['where'])) {
			$this->CI->db->where($a['where']);
		}

		if (isset($a['order'])) {
			$this->CI->db->order_by($a['order']);
		}

		if (isset($a['limit'])) {
			$this->CI->db->limit($a['limit']);
		}

		$rs = $this->CI->db->get($a['table']);
		$list = array();

		while ($row = $rs->unbuffered_row('array')) {
			$list[] = $row;
		}

		return $list;
	}

	public function group_ids($a)
	{
		$rows = $this->CI->db->select($a['field'])->where($a['where'])->group_by($a['group'])->get($a['table'])->result_array();
		$ids = array();

		foreach ($rows as $v) {
			$ids[] = $v[$a['field']];
		}

		return implode(',', $ids);
	}

	public function fields($a)
	{
		$rows = $this->CI->db->select($a['field'])->where($a['where'])->get($a['table'])->result_array();
		$arr = array();

		foreach ($rows as $v) {
			$arr[] = $v[$a['field']];
		}

		return implode(',', $arr);
	}
}

defined('BASEPATH') || exit('No direct script access allowed');

?>
